<%
Class CList
  'Private Values
  Private INIT_SIZE
  Private INIT_GAP_SIZE

  Private mArr()' As Variant
  Private mCount
  Private mSize
  'Class Things
  Private Sub Class_Initialize()
    INIT_GAP_SIZE = 128
    INIT_SIZE = 1024
    mCount = 0
    mSize = INIT_SIZE
    Redim mArr(mSize)
  End Sub

  Private Sub Class_Terminate()

  End Sub
  'Public Property
  Public Property Get Item(ByVal index)
    If index > mCount Or index < 1 Then
      Err.Raise vbObjectError + 10032301, ,"[SunSoft]索引超出范围"
    End If
    Item = mArr(index)
  End Property

  Public Property Let Item(ByVal index, Value)
    If index > mCount Or index < 1 Then
      Err.Raise vbObjectError + 10032301, ,"[SunSoft]索引超出范围"
    End If
    mArr(index) = Value
  End Property

  Public Property Get Count()' As Long
    Count = mCount
  End Property
  'Private Methods
  Private Sub resize()
    mSize = mSize + INIT_GAP_SIZE
    ReDim Preserve mArr(mSize)
  End Sub

  Private Function m_ExistValue(ByVal Value)' As Boolean
    Dim i
    
    i = 0
    m_ExistValue = False
    For i = 1 To mCount
      If mArr(i) = Value Then
        m_ExistValue = True
        Exit Function
      End If
    Next 
  End Function
  'Public Methods
  Public Function Add(ByVal Value)' As CList
    If mCount >= mSize Then
      Call resize
    End If
    mCount = mCount + 1
    mArr(mCount) = Value
    Set Add = Me
  End Function

  Public Function ToArray()' As String()
    Dim arr(), i
    i = 0
    Redim arr(0)
    arr(0) = ""

    If mCount = 0 Then
      ToArray = arr
      Exit Function
    End If
    
    ReDim arr(mCount - 1)
    For i = 0 To mCount - 1
      arr(i) = CStr(mArr(i + 1))
    Next
    ToArray = arr
  End Function

  Public Function Join(ByVal Separator, ByVal Start)' As String
    Dim joins, i

    joins = "" : i = 0
    
    If mCount = 0 Then
      Join = ""
      Exit Function
    End If

    For i = Start To mCount
      joins = joins & Separator & CStr(mArr(i))
    Next
    
    joins = Mid(joins, Len(Separator) + 1)
    
    Join = joins
  End Function

  Public Function WrapJoin(ByVal Separator, ByVal Wraper, ByVal Start)' As String
    Dim joins, i

    joins = "" : i = 0
    
    If mCount = 0 Then
      WrapJoin = ""
      Exit Function
    End If

    For i = Start To mCount
      joins = joins & Separator & Wraper & CStr(mArr(i)) & Wraper
    Next
    
    joins = Mid(joins, Len(Separator) + 1)
    
    WrapJoin = joins
  End Function

  Public Sub Clear()
    Call Class_Initialize
  End Sub

  Public Function LoadFromString(ByVal DataString, ByVal Delimiter)' As CList
    Dim mLArr, i

    i = 0

    Call Clear
    If DataString = "" Then
      Set LoadFromString = Me
      Exit Function
    End If
    mLArr = Split(DataString, Delimiter)
    For i = 0 To UBound(mLArr)
      Add mLArr(i)
    Next
    Set LoadFromString = Me
  End Function

  Public Function DistinctAdd(ByVal Value)' As CList
    If m_ExistValue(Value) = False Then
      Set DistinctAdd = Add(Value)
    Else
      Set DistinctAdd = Me
    End If
  End Function
End Class
%>